//
//  AddressDelegate.m
//  cTypica
//
//  Created by David Kavanagh on 11/25/08.
//  Copyright 2008 directThought. All rights reserved.
//

#import "AddressDelegate.h"


@implementation AddressDelegate
@synthesize addresses;

+ (id)delegate {
	AddressDelegate *ret = [self alloc];
	return ret;
}

// XML parser delegate methods
- (void)parser: (NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
	if ([elementName isEqualToString:@"addressesSet"]) {
		self.addresses = [[NSMutableArray alloc] initWithCapacity:1];
	}
	else if ([elementName isEqualToString:@"item"]) {
		item = [AddressInfo alloc];
		
	}
}

- (void)parser: (NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
	NSString *cleanString = [currentStringValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
	[currentStringValue setString:@""];
	if ([elementName isEqualToString:@"addressesSet"]) {
	}
	else if ([elementName isEqualToString:@"item"]) {
		[self.addresses addObject:item];
		[item release];
		item = nil;
	}
	else if ([elementName isEqualToString:@"instanceId"]) {
		item.instanceId = cleanString;
	}
	else if ([elementName isEqualToString:@"publicIp"]) {
		item.publicIp = cleanString;
	}

}
@end
